package exercise6;

public class Exercise13_05 {
    public static void main(String []args){
        Circle circle1=new Circle(2);
        Circle circle2=new Circle(3);

        Rectangle rectangle1=new Rectangle(1,2);
        Rectangle rectangle2=new Rectangle(2,3);

        System.out.println("最大的面积是：");
        System.out.println(Circle.max(circle1,circle2).getArea());

        System.out.println("最大的矩形面积是：");
        System.out.println(Rectangle.max(rectangle1,rectangle2).getArea());
    }
}

//实现接口
abstract class My_Geometric implements Comparable<My_Geometric>{
    public abstract double getArea();

    @Override
    public int compareTo(My_Geometric o) {
        return Double.compare(getArea(), o.getArea());
    }
    //比较最大值的方法
    public static My_Geometric max(My_Geometric o1,My_Geometric o2){
        if (o1.compareTo(o2)>0){
            return o1;
        }
        else{
            return o2;
        }
    }

}

class Circle extends My_Geometric{
    double r;

    //构造函数只包含半径
    public Circle(double r){
        this.r=r;
    }

    @Override
    public double getArea(){
        return Math.PI*Math.pow(r,2);
    }
}

class Rectangle extends My_Geometric{
    double weight;
    double height;

    public Rectangle(double weight,double height){
        this.weight=weight;
        this.height=height;
    }

    @Override
    public double getArea(){
        return height*weight;
    }


}